      				$(function(){
                    	$('#isIdCardNo,#truename,#province,#company,#mobile,#certificate,#number,#address,#grade_id,#subject_id,#email').bind({
                            blur:function(){
                                FormValidation(this);
                            },
                            focus:function(){
                                var _tipsbox=$(this).nextAll('label.tips');
                                _tipsbox.removeClass('moren');
                                if(_tipsbox.hasClass('eer')){
                                    
                                }else{
                                    _tipsbox.addClass('default');
                                }
                            }
                        });
                        $('button[id="reg_submit_btn"]').click(function() {
                            var r = reg_validation();
							if(r == true){
                                                            
								$('form').submit();
							}
                        });
                    });
					
					/*确认方法*/
                    function reg_validation(){
						var _err=$('#userreg').find('label.tips');
						if(!_err.hasClass('eer')){
							FormValidation($('#isIdCardNo')[0]);
							FormValidation($('#province')[0]);
							FormValidation($('#truename')[0]);
							FormValidation($('#mobile')[0]);
							FormValidation($('#company')[0]);
							FormValidation($('#certificate')[0]);
							FormValidation($('#number')[0]);
							FormValidation($('#address')[0]);
                            FormValidation($('#grade_id')[0]);
                            FormValidation($('#subject_id')[0]);
                            FormValidation($('#email')[0]);
					    }
                        if(_err.hasClass('eer')){	
                            return false;
                        }else{
							return true;
                        }
                    }
                    function setState (obj,cls,text){
                        var _tips=$(obj).nextAll('label.tips');
                        var _defalut_text=_tips.text();
                        _tips.attr('class','tips '+cls);
                        _tips.find('span').hide();
                        _tips.find('label').remove();
						_tips.text('');
						if(cls=='eer'){
							_tips.addClass('err-back');
						}else{
							_tips.removeClass('err-back');
						}
                        _tips.append(text); 
                    };
                    
                    function checkForm(obj,func){
                        var rules={
                            email 		: "^[A-Za-z0-9\d]+([-_\.\+]*[A-Za-z0-9\d])*@([a-z0-9\d][a-z0-9\d-]{0,61}[a-z0-9\d]\.)+[a-z\d]{2,6}$", 
                            required	: "^.+$",
                            password	: "^.+$",
                            trueName	: '',
							province    : '',
							address     : '',
							company     : '',
							certificate : '',
                            mobile		: "^1[3|5|8][0-9][0-9]{8}$",
                            isCN		: '^[chr(0xa1)-chr(0xff)]+$',
                            numeric		: "^[0-9]+$",
                            loginname	: "^[a-z][a-z0-9-_.]+$",
                            phone		: "^([0-9]{0}|[0-9]{3,4})[-]{0,1}[0-9]{7,8}$",
                            idcard		: "^([0-9]{15}|[0-9]{18})$",
                            zip			: "^[0-9]{6}$"
                        };
                        var arg=arguments;
                        if(arg.length>0){
                            var reg	= new RegExp(rules[obj.type] , "gi");
                            var result	= reg.test(obj.value)?true:false;
                            if(arg.length>1&&typeof(arg[1])=='function'){ 
                                return func(result);
                            }else{
                                return result;
                            }
                        }else{
                            alert('请设置您要检查的内容');
                        }
                    };
                    function checkPassword(p1,p2){
                        if(p1.value.length>5&&p1.value.length<17){ 
                            if(p2.value.length>0){ 
                                var _match=p1.value==p2.value?'':'请核对前后密码是否一致';
                                if(p1.value==p2.value){
                                    setState(p1,'suc','');
                                }else{
                                    setState(p1,'eer',_match);
                                }
                            }else{
                                setState(p1,'suc','');
                            }
                        }else{
                            setState(p1,'eer','6-16个字符，密码字母区分大小写');
                        }
                    };
					//--身份证号码验证-支持新的带x身份证
					function isIdCardNo() 
					{
						var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
						var error;
						var varArray = new Array();
						var intValue;
						var lngProduct = 0;
						var intCheckDigit;
						var intStrLen = $('#isIdCardNo').val().length;
						var idNumber =  $('#isIdCardNo').val();    
						// initialize
						if ((intStrLen != 15) && (intStrLen != 18)) {
							error = "输入身份证号码长度不对！";
							//alert(error);
							//frmAddUser.txtIDCard.focus();
							setState($('#isIdCardNo')[0],'eer',error);
							return false;
						}    
						// check and set value
						for(i=0;i<intStrLen;i++) {
							varArray[i] = idNumber.charAt(i);
							if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
								error = "错误的身份证号码！.";
								//alert(error);
								//frmAddUser.txtIDCard.focus();
								setState($('#isIdCardNo')[0],'eer',error);
								return false;
							} else if (i < 17) {
								varArray[i] = varArray[i]*factorArr[i];
							}
						}
						if (intStrLen == 18) {
							//check date
							var date8 = idNumber.substring(6,14);
							if (checkDate(date8) == false) {
								error = "身份证号码信息不正确！.";
								//alert(error);
								setState($('#isIdCardNo')[0],'eer',error);
								return false;
							}        
							// calculate the sum of the products
							for(i=0;i<17;i++) {
								lngProduct = lngProduct + varArray[i];
							}        
							// calculate the check digit
							intCheckDigit = 12 - lngProduct % 11;
							switch (intCheckDigit) {
								case 10:
									intCheckDigit = 'X';
									break;
								case 11:
									intCheckDigit = 0;
									break;
								case 12:
									intCheckDigit = 1;
									break;
							}        
							// check last digit
							if (varArray[17].toUpperCase() != intCheckDigit) {
								error = "身份证号码信息不正确 ";
								//alert(error);
								setState($('#isIdCardNo')[0],'eer',error);
								return false;
							}
						} 
						else{        //length is 15
							//check date
							var date6 = idNumber.substring(6,12);
							if (checkDate(date6) == false) {
								error ="身份证号码信息不正确！.";
								setState($('#isIdCardNo')[0],'eer',error);
								return false;
							}
						}
						//alert ("Correct.");
						setState($('#isIdCardNo')[0],'suc','');
						return true;
					}
					
					function checkDate(date){
						return true;
					}
                    function FormValidation(n){
                        var rules={
                            isIdCardNo:function(){
                                isIdCardNo();
                            },
                            repassword:function(){
                                if(n.value!=''){
                                    var _pass=$('#regpassword')[0];
                                    if(n.value==_pass.value){
                                        setState(n,'suc','');
                                    }else{
                                        setState(n,'eer','请核对前后密码是否一致');
                                    }
                                }
                            },
                            truename:function(){
                                if(n.value.length>1){ 
                                    checkForm({'value':n.value,'type':'isCN'},function(t){
                                        if(t){
                                            setState($('#truename')[0],'eer','请输入真实姓名');
                                        }else{
                                            setState($('#truename')[0],'suc','');
                                        };
                                    });
                                }else{
                                    setState($('#truename')[0],'eer','请输入真实姓名');
                                }
                            },
							province:function(){
								var _province=$('#province').val();
							    if(_province!=''){ 
                                    setState($('#province')[0],'suc','');
                                }else{
                                    setState($('#province')[0],'eer','请输入联系地址');
                                }
							},
                         	grade_id:function(){
								var _grade_id=$('#grade_id').val();
							    if(_grade_id!=''){ 
                                    setState($('#grade_id')[0],'suc','');
                                }else{
                                    setState($('#grade_id')[0],'eer','请选择您所教的年级');
                                }
							},
                          	subject_id:function(){
								var _subject_id=$('#subject_id').val();
							    if(_subject_id!=''){ 
                                    setState($('#subject_id')[0],'suc','');
                                }else{
                                    setState($('#subject_id')[0],'eer','请选择您所教的学科');
                                }
							},
							company:function(){
                                if(n.value.length>1&&n.value.length<51){ 
                                    checkForm({'value':n.value,'type':'isCN'},function(t){
                                        if(t){
                                            setState($('#company')[0],'eer','请输入您所在的学校名');
                                        }else{
                                            setState($('#company')[0],'suc','');
                                        };
                                    });
                                }else{
                                    setState($('#company')[0],'eer','请输入您所在的学校名');
                                }
                            },
							certificate:function(){
								var _certificate=$('#certificate').val();
								if(_certificate!=''){ 
                                    setState($('#certificate')[0],'suc','');
                                }else{
                                    setState($('#certificate')[0],'eer','请输选择教师资格证类别 ');
                                }
							},
							number:function(){
                                if(n.value.length>1&&n.value.length<51){ 
                                    setState($('#number')[0],'suc','');
                                }else{
                                    setState($('#number')[0],'eer','请输入教师资格证书编号');
                                }
                            },
                            mobile:function(){
                                checkForm({'value':n.value,'type':'mobile'},function(t){
                                var _box=$('#mobile')[0];
                                    if(t){
                                        setState($('#mobile')[0],'suc','');
                                    }else{
                                        setState(_box,'eer','填写的手机号码错误');
                                    }
                                });
                            },
                            email:function(){
                                checkForm({'value':n.value,'type':'email'},function(t){
                                var _box=$('#email')[0];
                                    if(t){
                                        setState($('#email')[0],'suc','');
                                    }else{
                                        setState(_box,'eer','请填写正确的邮箱');
                                    }
                                });
                            },
                            grade:function(){
                                if(n.value!=''){
                                    setState(n,'suc','');
                                }else{
                                    setState(n,'eer','请选择年级');
                                }
                            },
                            code:function(){
                                checkForm({'value':n.value,'type':'numeric'},function(t){
                                var _box=$('#code')[0];
                                    if(t){
                                        //setState($('#code')[0],'suc','');
                                        $.ajax({
                                            async: false,
                                            type: "POST",
                                            url: "http://www.xueersi.com/users/getVerificationCode",
                                            data: "verificationCode=" + n.value,
                                            dataType: "json",
                                            timeout: 7000,
                                            success: function(result) {	
                                                sign = result.sign;
                                                if(sign){
                                                    setState(n,'suc','');
                                                }else{
                                                    setState(n,'eer','验证码填写错误，请重试!');
                                                    changeVerificationImg('verificationImg');
                                                }
                                            },
                                            error: function() {
                                                //alert('数据读取错误,请重试..');
                                                return false;
                                            }
                                        });
                                    }else{
                                        setState(_box,'eer','请输入验证码!');
                                    }
                                });
                            },
                            provisions:function(){
                                if(n.checked){
                                    setState(n,'suc','');
                                }else{
                                    setState(n,'eer','请接收注册条款');
                                }
                            },
						   address:function(){
						        var _address=$('#address').val();
							    if(_address!=''){ 
                                    setState($('#address')[0],'suc','');
                                }else{
                                    setState($('#address')[0],'eer','请输入联系地址');
                                }
						   }
                        };
                        rules[n.id]();
                    };
                    
                    function checkPass(d){
                        var _p=$('#regpassword')[0];
                        var _v = _p.value, _len = _v.length, tip, cls;
                        var W = /^[A-Z]+$/.test(_v), w = /^[a-z]+$/.test(_v), d = /^\d+$/.test(_v), _ = /^[^a-zA-Z0-9]+$/.test(_v);
                        var WW = /[A-Z]+/.test(_v), ww = /[a-z]+/.test(_v), dd = /\d+/.test(_v), __ = /[^a-zA-Z0-9]+/.test(_v), zz = /[\u4e00-\u9fa5]/.test(_v);
                        
                        if(_len<6){
                            setState(_p,'eer','密码长度不能少于6个字符');
                        }else if(_len>16){
                            setState(_p,'eer','密码长度不能多于16个字符');
                        }else{
                            if (zz || WW && ww && dd || ww && dd && __ || WW && dd && __ || WW && ww && __) {
                                tip = (_len < 8 ? '不错' : '很好');
                                cls = (_len < 8 ? 'g3' : 'g4');
                                num = (_len < 8 ? 30 : 40);
                                setState(_p,'suc check-pass','<em>密码强度：</em><i><s style="width:'+num+'px"></s></i><em>'+tip+'</em>');
                            }else if (WW && ww || WW && dd || WW && __ || ww && dd || ww && __ || dd && __) {
                                tip = (_len < 8 ? '一般' : '不错');
                                cls = (_len < 8 ? 'g2' : 'g3');
                                num = (_len < 8 ? 20 : 30);
                                setState(_p,'suc check-pass','<em>密码强度：</em><i><s style="width:'+num+'px"></s></i><em>'+tip+'</em>');
                            }else if (W || w || d || _) {
                                tip = (_len < 10 ? '弱' : '一般');
                                cls = (_len < 10 ? 'g1' : 'g2');
                                num = (_len < 8 ? 10 : 20);
                                setState(_p,'suc check-pass','<em>密码强度：</em><i><s style="width:'+num+'px"></s></i><em>'+tip+'</em>');
                            }else {
                                setState(_p,'eer','请检查密码是否符合输入要求');
                                return false;
                            }
                        }
                    };
            